/**
 * @file
 * @author Ivan Babushkin (jogrms@gmail.com)
 * @date 10.06.2010
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QtWebKit/QWebView>
#include <QPushButton>
#include <qodefault.h>
#include <webview.h>
#include <cmdedit.h>
#include <QAction>
#include <toolbutton.h>

class MainWindow: public QMainWindow {
	Q_OBJECT

	public:
		
		QString commandOpen;
		QString commandTabOpen;
		QString commandTabClose;
		QString commandExit;

		MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
		~MainWindow();
		 
		struct QOSettings getSettings();
		WebView* currentWebView();
		WebView* createNewTab();

	private:

		QUrl lastUrl;
		QStringList commands;
		CmdEdit *cmdEdit;
		ToolButton *infoButton;
		QAction *actionOpen;
		QAction *actionTabOpen;
		QAction *actionTabNew;
		QAction *actionTabNext;
		QAction *actionTabClose;
		QAction *actionEsc;
		QAction *actionExit;
		struct QOSettings settings;
		QList<WebView*> webViews;
		QList<QPushButton*> pageButtons;
		void processCmd(QString cmdLine);
		void openUrl(QString url, int page);
		void openUrl(QUrl url, int page);
		void init();
		void openFile(QString fileName, int page);
		void openFile(QString fileName);
		int currentPage;
		void showCmdEdit(QString cmd);
		void openUrlNewTab(QString url, bool switchTo = false);
		void openUrlNewTab(QUrl url, bool switchTo = false);
		QAction *pageActionNewTab;

	protected:

		void closeEvent(QCloseEvent *event);
		void resizeEvent(QResizeEvent *event);
		void keyPressEvent(QKeyEvent *event);
		void wheelEvent(QWheelEvent *event);

	private slots:

		void runEsc();
		void cmdEditReturnPressed();
		void runTabNext();
		void runTabClose();
		void runExit();

	public slots:

		void runTabNew();
		void loadStarted();
		void loadProgress(int progress);
		void loadFinished(bool ok);
};

#endif // MAINWINDOW_H
